package com.fanshilz.flower2025.apps.admin.sysRole.resp;

import com.mybatisflex.annotation.RelationOneToMany;
import lombok.Data;

import java.sql.Timestamp;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class SysRoleTableDetailResp {

    private Long roleId;

    private String roleName;

    private String roleCode;

    private Timestamp createTime;

    private Integer createUserId;

    private String createUserName;

    private Integer updateUserId;

    private Timestamp updateTime;

    private String updateUserName;

    @RelationOneToMany(selfField = "roleId", targetTable = "sys_role_route", targetField = "roleId")
    private List<RoleRouteDetailResp> roleRouteIds;

    private List<Long> authorityTree;

    public void setRoleRouteIds(List<RoleRouteDetailResp> roleRouteIds) {
        this.roleRouteIds = roleRouteIds;
        setAuthorityTree(roleRouteIds.stream().map(RoleRouteDetailResp::getRouteId).collect(Collectors.toList()));
    }

    @Data
    public static class RoleRouteDetailResp {

        private Long roleId;

        private Long routeId;

    }

}
